package com.example.staticresourcesdeal.controller;

import com.example.staticresourcesdeal.pojo.TestObj;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.ArrayList;
import java.util.List;

@Controller
public class TestController {
    @RequestMapping("/KnowledgePoint1")
    public ModelAndView KnowledgePoint1(){
        /*thymeleaf掌管的页面里使用的数据，只能通过ModelAndView系列设置参数，才不会爆红，才有提示*/
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("obj",new TestObj(1,"TestObj"));
        modelAndView.setViewName("KnowledgePoint1");
        return modelAndView;
    }
    @RequestMapping("/KnowledgePoint2")
    public ModelAndView KnowledgePoint2(int num,String name){
        ModelAndView modelAndView = new ModelAndView();
        List<TestObj> objList=new ArrayList<>();
        for(int i=1;i<=3;i++)
            objList.add(new TestObj(num,name));
        modelAndView.addObject("objList",objList);
        modelAndView.addObject("obj",new TestObj(1,"TestObj"));
        modelAndView.setViewName("KnowledgePoint2");
        return modelAndView;
    }
}
